Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Packet diagram can use bit counts - implements #5978 #5980

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

BryanCrotazGivEnergy
Copy link

@BryanCrotazGivEnergy BryanCrotazGivEnergy commented Oct 18, 2024

📑 Summary

Resolves #5978

📏 Design Decisions

Added bit count to parser language and calculate start and end of each field on the fly

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added necessary unit/e2e tests.
  • 📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features.
  • 🦋 If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Copy link

changeset-bot bot commented Oct 18, 2024

⚠️ No Changeset found

Latest commit: c828867

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Oct 18, 2024

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit c828867
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/6713e344b794ca000886f0c8
😎 Deploy Preview https://deploy-preview-5980--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

pkg-pr-new bot commented Oct 18, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/mermaid-js/mermaid@5980
pnpm add https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/mermaid-zenuml@5980
pnpm add https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/layout-elk@5980
pnpm add https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/parser@5980

commit: c828867

@BryanCrotazGivEnergy
Copy link
Author

Tried to add a feature changeset but I get Error: Failed to find where HEAD diverged from master. Does master exist?

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 0% with 32 lines in your changes missing coverage. Please review.

Project coverage is 4.64%. Comparing base (d16e46a) to head (c828867).
Report is 139 commits behind head on develop.

Files with missing lines Patch % Lines
packages/mermaid/src/diagrams/packet/parser.ts 0.00% 32 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #5980      +/-   ##
==========================================
- Coverage     4.64%   4.64%   -0.01%     
==========================================
  Files          374     374              
  Lines        51965   51985      +20     
  Branches       613     613              
==========================================
  Hits          2414    2414              
- Misses       49551   49571      +20     
Flag Coverage Δ
unit 4.64% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/mermaid/src/diagrams/packet/parser.ts 0.00% <0.00%> (ø)
---- 🚨 Try these New Features:

Copy link

argos-ci bot commented Oct 18, 2024

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No changes detected - Oct 19, 2024, 4:57 PM

@BryanCrotazGivEnergy
Copy link
Author

@aloisklink please review this PR - I think it's ready

@BryanCrotazGivEnergy BryanCrotazGivEnergy changed the title Packet diagram bit counts implements #5978 Feature: Packet diagram can use bit counts - implements #5978 Oct 19, 2024
@BryanCrotazGivEnergy
Copy link
Author

What's the process to get this approved?

@zanedp
Copy link

zanedp commented Nov 23, 2024

(I just copied the following to the #5978, in case that's a better location for syntax discussions.)

I was considering using the "packet" type as a way to draw a memory map, which would be byte-scale instead of bit-scale. I wonder if a different syntax that didn't "tie" the diagram to a particular unit of measure would be more flexible? Shorting to b would make it so both "bits" and "bytes" make sense. But maybe doing something like +5 to mean it's relative to the previous thing would work and be intuitive?

+16: Header
+32: Data
+4: Footer

Using + is similar to "relative time" in PlantUML's timing diagram.

Copy link
Member

@sidharthv96 sidharthv96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work @BryanCrotazGivEnergy, love the implementation and tests!
@zanedp makes a really good point, and I feel the + syntax looks better, and is easier to write & read. It'll also make the parser a bit simpler.

Do you mind modifying the syntax to the + based one? Thank you!

Current

packet-beta
title UDP Packet
0-15: "Source Port"
16-31: "Destination Port"
32-47: "Length"
48-63: "Checksum"
64-95: "Data (variable length)"

bit(s) syntax

packet-beta
title UDP Packet
16bits: "Source Port"
16bits: "Destination Port"
16bits: "Length"
16bits: "Checksum"
32bits: "Data (variable length)"

bit(s) syntax (mixed)

packet-beta
title UDP Packet
0-15: "Source Port"
16bits: "Destination Port"
32-47: "Length"
16bits: "Checksum"
32bits: "Data (variable length)"

+ syntax

packet-beta
title UDP Packet
+16: "Source Port"
+16: "Destination Port"
+16: "Length"
+16: "Checksum"
+32: "Data (variable length)"

+ syntax (mixed)

packet-beta
title UDP Packet
0-15: "Source Port"
+16: "Destination Port"
32-47: "Length"
+16: "Checksum"
+32: "Data (variable length)"

---
Using start and end bit counts can be difficult, especially when modifying a design. For this we add a bit count field, which starts from the end of the previous field automagically. Use `bit` or `bits` interchangeably to set the number of bits, thus:

````md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this means the example will not be rendered. Please use mermaid-example directly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I don't understand - adding what?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping with ````md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In Packet drawings, allow bit count as well as start-end
4 participants